package com.weiyi.mashangzhu.Roomer.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.weiyi.mashangzhu.API.API;
import com.weiyi.mashangzhu.Application.MyApp;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Roomer.Activity.HouseDetailsActivity;
import com.weiyi.mashangzhu.Roomer.Activity.RecommendActivity;
import com.weiyi.mashangzhu.Roomer.Bean.ActivityBean;
import com.weiyi.mashangzhu.Roomer.Bean.HouseListBean;
import com.weiyi.mashangzhu.Roomer.Bean.MapInfoBean;

import java.util.List;

/**
 * Created by win7 on 2017/9/21.
 */

public class MapViewPagerAdapter extends PagerAdapter {
    private Context context;
    private List<MapInfoBean> list;
    private View mCurrentView;

    public MapViewPagerAdapter(Context context, List<MapInfoBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        mCurrentView = (View) object;
    }

    public View getPrimaryItem() {
        return mCurrentView;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
//        // TODO Auto-generated method stub
        View view;
        view = View.inflate(context, R.layout.item_vp_houselist, null);
        ImageView img = (ImageView) view.findViewById(R.id.img);
        TextView price = (TextView) view.findViewById(R.id.price);
        TextView title = (TextView) view.findViewById(R.id.title);
        TextView type = (TextView) view.findViewById(R.id.type);
        TextView address = (TextView) view.findViewById(R.id.address);
        TextView grade = (TextView) view.findViewById(R.id.grade);

        Glide.with(context).load(API.BaseApi_url + MyApp.getUrlList3(list,position).get(0)).error(R.mipmap.errer).into(img);
        title.setText(list.get(position).getHTitle()+"");
        price.setText("¥"+list.get(position).getHPrice());
        type.setText(list.get(position).getHRoom()+"居  |  ");
        address.setText(list.get(position).getHDistrict()+"");
        grade.setText(list.get(position).getScoreave()+"");
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, HouseDetailsActivity.class);
                intent.putExtra("id",list.get(position).getId()+"");
                intent.putExtra("city",list.get(position).getHCity()+"");
                context.startActivity(intent);
            }
        });
        container.addView(view);
        return view;
    }
}
